
*******************************************************************************
*** Description: 	This document provides the code for reproducing the 	***
***					figures in the paper, "Political Knowledge, the 	    ***
***					Decision Calculus, and Proximity Voting, which is     	***
***					authored by Shane P. Singh and Jason Roy				***
***					and appears in Electoral Studies.						***
*******************************************************************************


**************
**************
*Set the Version                                                                                                                                 
**************
**************
version 11.2


**************
**************
*Set Your Own Pathway                                                                                                                         
**************
**************
global pw  "/Users/singh/Desktop"


*******
*CASE SPECIFIC-DATA
*******
use "$pw/ES_Proximity_Voting_Case_Data.dta", clear

***Figure 2
nbreg  n_infolinks polknow01 age female grad canada, dispersion(constant) 
estimates table, b(%9.3f)  se(%9.3f) p(%9.3f)
margins, at(polknow01 =(0.0(.1)1)) atmeans vsquish post predict(n) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp1.dta", replace)
preserve
use "$pw/graphtemp1.dta", clear 
gen at = ((_n-1)/10) 
gen ll = min90
gen ul = max90
gen prob = estimate

twoway (rarea ll ul at in 1/11, color(green) lcolor(black)) (line prob at in 1/11, lcolor(black))  ,  ///
	xtitle(Political Knowledge) ytitle(Predicted Number of Links Accessed) scheme(s1color)  xscale(range(0 1)) xlabel(0[.2]1)  aspectratio(1) /// 
	legend(off) name("links", replace) ///

restore


nbreg  hardcon polknow01 age female grad canada, dispersion(constant) 
estimates table, b(%9.3f)  se(%9.3f) p(%9.3f)
margins, at(polknow01 =(0.0(.1)1)) atmeans vsquish post predict(n) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp1.dta", replace)
preserve
use "$pw/graphtemp1.dta", clear 
gen at = ((_n-1)/10) 
gen ll = min90
gen ul = max90
gen prob = estimate

twoway (rarea ll ul at in 1/11, color(green) lcolor(black)) (line prob at in 1/11, lcolor(black))  ,  ///
	xtitle(Political Knowledge) ytitle(Predicted Number of Cueing Links Accessed) scheme(s1color)  xscale(range(0 1)) xlabel(0[.2]1)  aspectratio(1) /// 
	legend(off) name("hardlinks", replace) ///

restore


graph combine links hardlinks, scheme(s1color) ysize(8) rows(2)





*******
*ALTERNATIVE SPECIFIC-DATA
*******
use "$pw/ES_Proximity_Voting_Alternative_Data.dta", clear

*Rescale Knowledge
egen polknowZ = std(polknow01) 

*code polknow to have 0 at 1sd below
gen polknowZEROatonebelow = polknowZ + 1

*code polknow to have 0 at 1sd above
gen polknowZEROatoneabove = polknowZ - 1

*interactions
gen polknowZEROatonebelowXidist =  ideodistind * polknowZEROatonebelow
gen polknowZEROatoneaboveXidist =  ideodistind * polknowZEROatoneabove


***Figure 3
clogit vchoice ideodistind polknowZEROatonebelowXidist  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp1.dta", replace)

clogit vchoice ideodistind polknowZEROatoneaboveXidist  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp2.dta", replace)

preserve
use "$pw/graphtemp1.dta", clear 
append using "$pw/graphtemp2.dta"
gen at = (_n/2) - .5
replace at = (_n/2) - 10 in 20/38
gen ll = min90
gen ul = max90
gen prob = estimate

twoway (rarea ll ul at in 1/19, color(blue) lcolor(black)) (line prob at in 1/19, lcolor(black)) (rarea ll ul at in 20/38, color(red) lcolor(black)) (line prob at in 20/38, lcolor(black))  ,  ///
	xtitle(Ideological Distance) ytitle(Pr(Vote for Party)) scheme(s1color)  xscale(range(0 9)) xlabel(0[1]9) yscale(range(0 .9)) ylabel(0[.3].9) /// 
	legend(order(1 "Low Knowledge" 3 "High Knowledge") rows(2)) aspectratio(1)  ///

restore




***Figure 4
egen linksnooutZ = std(linksnoout) 

*code linksnoout to have 0 at 1sd below
gen linksnooutatonebelow = linksnooutZ + 1

*code linksnoout to have 0 at 1sd above
gen linksnooutatoneabove = linksnooutZ - 1

*interactions
gen linksnooutatonebelowXidist =  ideodistind * linksnooutatonebelow
gen linksnooutatoneaboveXidist =  ideodistind * linksnooutatoneabove


*ideological distance X links
clogit vchoice ideodistind linksnooutatonebelowXidist  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp1.dta", replace)

clogit vchoice ideodistind linksnooutatoneaboveXidist  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp2.dta", replace)

preserve
use "$pw/graphtemp1.dta", clear 
append using "$pw/graphtemp2.dta"
gen at = (_n/2) - .5
replace at = (_n/2) - 10 in 20/38
gen ll = min90
gen ul = max90
gen prob = estimate

twoway (rarea ll ul at in 1/19, color(blue) lcolor(black)) (line prob at in 1/19, lcolor(black)) (rarea ll ul at in 20/38, color(red) lcolor(black)) (line prob at in 20/38, lcolor(black))  ,  ///
	xtitle(Ideological Distance) ytitle(Pr(Vote for Party)) scheme(s1color)  xscale(range(0 9)) xlabel(0[1]9) yscale(range(0 .9)) ylabel(0[.3].9) aspectratio(1) /// 
	legend(order(1 "Low Number of Links" 3 "High Number of Links") rows(2))  name("vchoice_nlinks", replace) ///

restore



*ideological distance X cueing links
egen hardconZ = std(hardcon)  

*code hardcon to have 0 at 1sd below
gen hardconatonebelow = hardconZ + 1

*code hardcon to have 0 at 1sd above
gen hardconatoneabove = hardconZ - 1

*interactions
gen hardconatonebelowXidist =  ideodistind * hardconatonebelow
gen hardconatoneaboveXidist =  ideodistind * hardconatoneabove


clogit vchoice ideodistind hardconatonebelowXidist  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp1.dta", replace)

clogit vchoice ideodistind hardconatoneaboveXidist  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp2.dta", replace)

preserve
use "$pw/graphtemp1.dta", clear 
append using "$pw/graphtemp2.dta"
gen at = (_n/2) - .5
replace at = (_n/2) - 10 in 20/38
gen ll = min90
gen ul = max90
gen prob = estimate

twoway (rarea ll ul at in 1/19, color(blue) lcolor(black)) (line prob at in 1/19, lcolor(black)) (rarea ll ul at in 20/38, color(red) lcolor(black)) (line prob at in 20/38, lcolor(black))  ,  ///
	xtitle(Ideological Distance) ytitle(Pr(Vote for Party)) scheme(s1color)  xscale(range(0 9)) xlabel(0[1]9) yscale(range(0 .9)) ylabel(0[.3].9) aspectratio(1) /// 
	legend(order(1 "Low Number of Cueing Links" 3 "High Number of Cueing Links") rows(2))  name("vchoice_ncuelinks", replace) ///

restore



graph combine vchoice_nlinks vchoice_ncuelinks, scheme(s1color) ysize(10) rows(2)




***Figure 5
*Low Links, Low Knowledge
gen numatonebelowXidist =  ideodistind * linksnooutatonebelow
gen threeway_lowlinks_lowknow = ideodistind * polknowZEROatonebelow * linksnooutatonebelow

clogit vchoice ideodistind polknowZEROatonebelowXidist   numatonebelowXidist threeway_lowlinks_lowknow  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp1.dta", replace)

*Low Links, High Knowledge
gen threeway_lowlinks_highknow = ideodistind * polknowZEROatoneabove * linksnooutatonebelow

clogit vchoice ideodistind polknowZEROatoneaboveXidist   numatonebelowXidist threeway_lowlinks_highknow  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp2.dta", replace)

preserve
use "$pw/graphtemp1.dta", clear 
append using "$pw/graphtemp2.dta"
gen at = (_n/2) - .5
replace at = (_n/2) - 10 in 20/38
gen ll = min90
gen ul = max90
gen prob = estimate

twoway (rarea ll ul at in 1/19, color(blue) lcolor(black)) (line prob at in 1/19, lcolor(black)) (rarea ll ul at in 20/38, color(red) lcolor(black)) (line prob at in 20/38, lcolor(black))  ,  ///
	xtitle(Ideological Distance) ytitle(Pr(Vote for Party)) scheme(s1color)  xscale(range(0 9)) xlabel(0[1]9) yscale(range(0 .9)) ylabel(0[.3].9) /// 
	legend(order(1 "Low Number of Links and Low Knowledge" 3 "Low Number of Links and High Knowledge") rows(2))  name("vchoice_nlinks_know", replace) ///

restore

*High Links, Low Knowledge
gen numatoneaboveXidist =  ideodistind * linksnooutatoneabove
gen threeway_highlinks_lowknow = ideodistind * polknowZEROatonebelow * linksnooutatoneabove

clogit vchoice ideodistind polknowZEROatonebelowXidist   numatoneaboveXidist threeway_highlinks_lowknow  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp1.dta", replace)

*High Links, High Knowledge
gen threeway_highlinks_highknow = ideodistind * polknowZEROatoneabove * linksnooutatoneabove

clogit vchoice ideodistind polknowZEROatoneaboveXidist   numatoneaboveXidist threeway_highlinks_highknow  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp2.dta", replace)



preserve
use "$pw/graphtemp1.dta", clear 
append using "$pw/graphtemp2.dta"
gen at = (_n/2) - .5
replace at = (_n/2) - 10 in 20/38
gen ll = min90
gen ul = max90
gen prob = estimate

twoway (rarea ll ul at in 1/19, color(blue) lcolor(black)) (line prob at in 1/19, lcolor(black)) (rarea ll ul at in 20/38, color(red) lcolor(black)) (line prob at in 20/38, lcolor(black))  ,  ///
	xtitle(Ideological Distance) ytitle(Pr(Vote for Party)) scheme(s1color)  xscale(range(0 9)) xlabel(0[1]9) yscale(range(0 .9)) ylabel(0[.3].9) /// 
	legend(order(1 "High Number of Links and Low Knowledge" 3 "High Number of Links and High Knowledge") rows(2))  name("vchoice_nlinks_know2", replace) ///

restore



*Low Cueing Links, Low Knowledge
gen hcatonebelowXidist =  ideodistind * hardconatonebelow
gen threeway_lowHlinks_lowknow = ideodistind * polknowZEROatonebelow * hardconatonebelow

clogit vchoice ideodistind polknowZEROatonebelowXidist   hcatonebelowXidist threeway_lowHlinks_lowknow  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp1.dta", replace)

*Low Cueing Links, High Knowledgee
gen threeway_lowHlinks_highknow = ideodistind * polknowZEROatoneabove * hardconatonebelow

clogit vchoice ideodistind polknowZEROatoneaboveXidist   hcatonebelowXidist threeway_lowHlinks_highknow  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp2.dta", replace)

preserve
use "$pw/graphtemp1.dta", clear 
append using "$pw/graphtemp2.dta"
gen at = (_n/2) - .5
replace at = (_n/2) - 10 in 20/38
gen ll = min90
gen ul = max90
gen prob = estimate

twoway (rarea ll ul at in 1/19, color(blue) lcolor(black)) (line prob at in 1/19, lcolor(black)) (rarea ll ul at in 20/38, color(red) lcolor(black)) (line prob at in 20/38, lcolor(black))  ,  ///
	xtitle(Ideological Distance) ytitle(Pr(Vote for Party)) scheme(s1color)  xscale(range(0 9)) xlabel(0[1]9) yscale(range(0 .9)) ylabel(0[.3].9) /// 
	legend(order(1 "Low Number of Cueing Links and Low Knowledge" 3 "Low Number of Cueing Links and High Knowledge") rows(2))  name("vchoice_ncuelinks_know", replace) ///

restore



*High Cueing Links, Low Knowledge
gen hcatoneaboveXidist =  ideodistind * hardconatoneabove
gen threeway_highHlinks_lowknow = ideodistind * polknowZEROatonebelow * hardconatoneabove

clogit vchoice ideodistind polknowZEROatonebelowXidist   hcatoneaboveXidist threeway_highHlinks_lowknow  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp1.dta", replace)

*High Cueing Links, High Knowledge
gen threeway_highHlinks_highknow = ideodistind * polknowZEROatoneabove * hardconatoneabove

clogit vchoice ideodistind polknowZEROatoneaboveXidist   hcatoneaboveXidist threeway_highHlinks_highknow  , group(_id) 
margins, at(ideodistind =(0.1(.5)9.1)) atmeans vsquish post predict(pu0) level(90)
parmest, format(estimate min90 max90) level(90)  saving("$pw/graphtemp2.dta", replace)



preserve
use "$pw/graphtemp1.dta", clear 
append using "$pw/graphtemp2.dta"
gen at = (_n/2) - .5
replace at = (_n/2) - 10 in 20/38
gen ll = min90
gen ul = max90
gen prob = estimate

twoway (rarea ll ul at in 1/19, color(blue) lcolor(black)) (line prob at in 1/19, lcolor(black)) (rarea ll ul at in 20/38, color(red) lcolor(black)) (line prob at in 20/38, lcolor(black))  ,  ///
	xtitle(Ideological Distance) ytitle(Pr(Vote for Party)) scheme(s1color)  xscale(range(0 9)) xlabel(0[1]9) yscale(range(0 .9)) ylabel(0[.3].9) /// 
	legend(order(1 "High Number of Cueing Links and Low Knowledge" 3 "High Number of Cueing Links and High Knowledge") rows(2))  name("vchoice_ncuelinks_know2", replace) ///

restore



graph combine ///
	vchoice_nlinks_know		///
	vchoice_ncuelinks_know	///
	vchoice_nlinks_know2 		///
	vchoice_ncuelinks_know2  	///
	, 	scheme(s1color) ysize(6) rows(2) iscale(.40005)
	
	




